var str = location.href;
var pos = str.indexOf("?")
if (pos > 0) {
    $('#userlogin').text(str.substring(pos + 1));
}

$('.exit').click(function() {
        location.href = "/login.html";
    })
    /*顶部导航栏点击跳转*/
$(function() {
    var navArr = ['tproxyInfo.html', 'innerNet.html', 'flowDispatch.html', 'networkOptimize.html', 'demand.html', 'logAnalysis.html']
    for (var i = 0; i < $('.headerNav li').length; i++) {
        (function(i) {
            $('.headerNav li').eq(i).click(function() {
                $(this).addClass('active').siblings().removeClass('active');
                $('.navInfo').text($(this).text());
                $('#mainFrame').removeAttr('src');
                $('#mainFrame').attr('src', navArr[i]);
            })
        }(i));
    }
});
$(function() {
    $('.manageUser').click(function() {
        $('.leftNavInfo').text('> 管理用户');
        $('#mainFrame').removeAttr('src');
        $('#mainFrame').attr('src', 'manageUser.html');
    })
})


$(document).on("click", "#sync", function() {
    var synurl = "http://" + apihost + "/v1/sync";
    var commiturl = "http://" + apihost + "/v1/sync/";
    http(synurl).then(
        function(data) {
            var resp = doSuccess(data)
            if (resp.code != 0) {
                return
            }
            var content = ""
            for (i in resp.value) {
                content += resp.value[i] + '<br>'
            }

            reConfirm(content, function() {
                http(commiturl, 'post', '').then(
                    function(data1) {
                        var resp1 = doSuccess(data1)
                        if (resp1.code == 0) {
                            layer.msg(resp1.desc, { icon: 1 });
                        }
                    },
                    function(a, b, c) {
                        doFail(a, b, c);
                    })
            })
        },
        function(a, b, c) {
            doFail(a, b, c);
        })
})
$(document).on("click", "#syncStat", function() {
    var statURL = "http://" + apihost + "/v1/sync/status";
    http(statURL).then(
        function(data) {
            var resp = doSuccess(data)
            layer.msg(resp.desc, { icon: 1 });
        },
        function(a, b, c) {
            doFail(a, b, c);
        })
})